package com.wanhe.qrcode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;

import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;


/**
 * Created by XieZaiWei on 2017/7/6.
 */

public class QRWebViewActivity extends Activity {

	public static final String KEY_URL = "url";
	BridgeWebView webView;
	private String mQrUrl;

	public static void startQRWebViewActivity(Activity act, String url) {
		Intent intent = new Intent(act, QRWebViewActivity.class);
		intent.putExtra(KEY_URL, url);
		act.startActivity(intent);
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.qr_webview_activity);
		webView = (BridgeWebView) findViewById(R.id.webView);
		webView.setKeepScreenOn(false);
		webView.setWebChromeClient(new WebChromeClient());
		WebSettings settings = webView.getSettings();
		settings.setDomStorageEnabled(true);
		settings.setAppCacheMaxSize(1024 * 1024 * 8);
		settings.setUseWideViewPort(true);
		settings.setLoadWithOverviewMode(true);
		settings.setBuiltInZoomControls(true);
		settings.setSupportZoom(true);
		settings.setJavaScriptEnabled(true);
		settings.setAppCacheEnabled(true);
		settings.setCacheMode(WebSettings.LOAD_DEFAULT);
		settings.setAllowFileAccess(true);

		mQrUrl = getIntent().getStringExtra(KEY_URL);
		webView.loadUrl(mQrUrl);

//		String ANDROID_ID = QRCodeUtil.getDeviceIDForServer(this);

		//        boolean id = webView.isHardwareAccelerated();
		webView.registerHandler("getPadID", new BridgeHandler() {
			@Override
			public void handler(String data, CallBackFunction function) {
				Log.e("MainActivity", "GetAll");
				String ANDROID_ID =  QRCodeUtil.getDeviceIDForServer(QRWebViewActivity.this);
                Log.e("MainActivity", "====ANDROID_ID==="+ANDROID_ID);
				function.onCallBack(ANDROID_ID);
			}
		});
	}
}
